package com.ddtech.business.course.controller;


import com.ddtech.business.course.entity.CourseType;
import com.ddtech.business.course.query.CourseTypeQuery;
import com.ddtech.business.course.service.CourseTypeService;
import com.ddtech.framework.log.aop.log.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程分类表 前端控制器
 * </p>
 *
 * @author bin_pu
 * @since 2023-02-06
 */
@Api(tags = "业务-课程分类管理")
@RestController
@RequestMapping("/course/course-type")
public class CourseTypeController {
    @Autowired
    private CourseTypeService courseTypeService;

    @Log("查询课程分类")
    @ApiOperation(value = "查询课程分类列表")
    @GetMapping(value = "/page-list")
    public ResponseEntity getPageList(CourseTypeQuery courseTypeQuery) {
        return new ResponseEntity(courseTypeService.pageList(courseTypeQuery), HttpStatus.OK);
    }

    @Log("查询课程分类树")
    @ApiOperation(value = "查询课程分类树")
    @GetMapping(value = "/tree")
    public ResponseEntity getTree(CourseTypeQuery courseTypeQuery) {
        return new ResponseEntity(courseTypeService.getTree(courseTypeQuery), HttpStatus.OK);
    }

    @Log("新增课程分类")
    @ApiOperation(value = "新增课程分类")
    @PostMapping(value = "/create")
    public ResponseEntity create(@RequestBody CourseType courseType) {
        courseTypeService.create(courseType);
        return new ResponseEntity(HttpStatus.OK);
    }

    @Log("删除课程分类")
    @ApiOperation(value = "删除课程分类")
    @PostMapping(value = "/del/{id}")
    public ResponseEntity del(@PathVariable String id) {
        courseTypeService.del(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}
